﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Shipment.aspx.cs" Inherits="UI_Mail_Shipment" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>运输</title>
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <style>
     #container{
       width:90%;/*宽度*/
       margin: 0 auto;/*边界auto为自动，这里用到了缩写形式意思为上下为0，
                      左右自动*/
     }
     #header{
       width:780px;
       height: 380px;
       margin: 0;
       overflow:hidden;/*防止div被撑开，超过div大小就隐藏*/
     }
     #midbody{
       width:780px;
       height: auto;
       margin:0;
       overflow:hidden;
     }
     #address{
       width:280px;
       height:650px;
       float:left;/*该层位于外层的左边*/
     }
     #ebayaddress{
       width:450px;
       height:600px;
     }
     .heBayAddress{
       position: relative;left:20px;top:65px;
     }
    </style>
    <script type="text/javascript">
      var idx = undefined;
      var setRowIdx = function (index) {
        idx = index;
      };

     $(function(){
       var eBayUserID = request.QueryString('ebayuserid');
       var orderID = request.QueryString('orderid');

       $('#postageservice').combobox({
         valueField: 'id',
         textField: 'text',
         data: [
           { id: 'service01', text: 'UK_RoyalMailFirstClassRecorded' },
           { id: 'service02', text: 'UK_RoyalMailFirstClassStandard' },
           { id: 'service03', text: 'UK_RoyalMailSecondClassStandard' },
           { id: 'service04', text: 'UK_RoyalMailAirmailInternational' },
           { id: 'service05', text: 'UK_OtherCourier48' },
           { id: 'service06', text: 'UK_RoyalMailSpecialDeliveryNextDay' },
           { id: 'service07', text: 'UK_OtherCourier' },
           { id: 'service08', text: 'UK_RoyalMailSecondClassRecorded' },
           { id: 'service09', text: 'UK_RoyalMailTracked' },
           { id: 'service10', text: 'UK_RoyalMailInternationalSignedFor' }
         ],
       });
      
       $.getJSON(
         './MailHandler.ashx?act=q&id=0601&ebayuserid=' + eBayUserID + '&orderid=' + orderID,
         function (data) {
           if (data.retVal == 0) {
             if (data.retSrc && data.retSrc.Information) {
               var info = data.retSrc.Information;
               for (i in info) {
                 $('#name').val(info[i].Name);
                 $('#company').val(info[i].Company);
                 $('#street').val(info[i].Street);
                 $('#city').val(info[i].City);
                 $('#county').val(info[i].County);
                 $('#country').val(info[i].Country);
                 $('#zipcode').val(info[i].ZipCode);
                 $('#telephone').val(info[i].Telephone);
                 $('#email').val(info[i].Email);
                 $('#postageservice').combobox('setValue', info[i].PostageService);
                 $('#ebayname').text(info[i].eBayName);
                 $('#ebaystreet').text(info[i].eBayStreet);
                 $('#ebaycity').text(info[i].eBayCity);
                 $('#ebaycounty').text(info[i].eBayCounty);
                 $('#ebaycountry').text(info[i].eBayCountry);
                 $('#ebayzipcode').text(info[i].eBayZipCode);
                 $('#shippingtype').val(info[i].MyShippingType);
                 $('#shippingcarrier').val(info[i].Company);
               }
             }
           }
           else {
             alert(data.retMsg);
           }
         });

       $('#product').datagrid({
         url: '../../TableHanders.aspx?act=q&tid=8018&type=0',
         columns: [[
           { field: 'UserCode', title: '产品代码' },
           { field: 'ProductName', title: '名称' },
           { field: 'Quantity', title: '订单数量' },
           { field: 'FQty', title: '库存数量' },
           { field: 'SQty', title: '锁定库存' },
           {
             field: 'operation', title: '动作',
             formatter: function (value, row, index)
             {
               return '<a id="op-' + index + '" href="javascript:void(0)" class="easyui-menubutton" data-options="menu:\'#mm\'" onmouseover="setRowIdx(' + index + ')">动作</a>';
             }
           }
         ]],
         queryParams: { 'ebayuserid': eBayUserID, 'orderid': orderID },
         onLoadSuccess: function (data) {
           for (i = 0; i < $(this).datagrid('getRows').length; i++) {
             $('#op-' + i).menubutton();
           }
         }
       });

       $('#btnimportinfo').click(function () {
         var eBayName = $('#ebayname').text();
         var eBayStreet = $('#ebaystreet').text();
         var eBayCity = $('#ebaycity').text();
         var eBayCounty = $('#ebaycounty').text();
         var eBayCountry = $('#ebaycountry').text();
         var eBayZipCode = $('#ebayzipcode').text();

         $('#country').val(eBayCountry);
         $('#name').val(eBayName);
         $('#street').val(eBayStreet);
         $('#city').val(eBayCity);
         $('#county').val(ebayCounty);
         $('#country').val(eBayCountry);
         $('#zipcode').val(eBayZipCode);
       });

       $('#mm').menu({
         onClick: function (item) {
           var rows = $('#product').datagrid('getRows');
           if (rows[idx]) {
             var olId = rows[idx].OrderLineItemID;
             var ebId = rows[idx].eBayUserID;
             var fsId = rows[idx].WarehouseId;
             var pId = rows[idx].ProductID;
             var orderStatusId = rows[idx].OrderStatusId;
             switch (item.id) {
               case "mm-add":
                 var ret = window.showModalDialog("../Orders/CustomerResolveBrowse.aspx?iType=I&olId=" + olId + "&ebId=" + ebId + "&fsId=" + fsId + "&ts=" + new Date().getTime(), "", "dialogHeight:300px;dialogWidth:610px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
                 if (ret) {
                   $("#product").datagrid('reload');
                 }
                 break;
               case "mm-delete":
                 if (orderStatusId == 2) {
                   alert("此订单已审核不可以删除");
                   return;
                 }
                 $.messager.confirm("请确认...", "确认删除?", function (value) {
                   if (value) {
                     var url = "../../TableHanders.aspx?act=d&tid=53&type=1&olId=" + olId + "&ebId=" + ebId + "&pId=" + pId + "&ts=" + new Date().getTime();
                     $.getJSON(
                         url,
                         function (data) {
                           var sdata = data[0];
                           var code = sdata.code;
                           if (code == 0) {
                             alert('删除成功');
                             $("#product").datagrid('reload');
                           }
                           else {
                             alert(sdata.msg);
                           }
                         }
                     );
                   }
                 });
                 break;
               case "mm-modify":
                 var ret = window.showModalDialog("../Orders/CustomerResolveBrowse.aspx?olId=" + olId + "&ebId=" + ebId + "&pid=" + pId + "&fsId=" + fsId + "&iType=U&ts=" + new Date().getTime(), "", "dialogHeight:300px;dialogWidth:610px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
                 if (ret) {
                   alert('操作完成');
                   $("#product").datagrid('reload');
                 }
                 break;
             }
           }
         }
       });

       $('#btnresend').click(function () {
         window.showModalDialog("../Orders/ReBuilderOrder.aspx?OrderId=" + orderID + "&EbayUserId=" + eBayUserID + "&ts=" + new Date().getTime(), "", "dialogHeight:400px;dialogWidth:875px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
       });

       $('#btnrefund').click(function () {
         window.showModalDialog("../Orders/CreateRefundOrder.aspx?OrderId=" + orderID + "&EbayUserId=" + eBayUserID + "&ts=" + new Date().getTime(), "", "dialogHeight:400px;dialogWidth:875px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
       });

       $('#btnsaveaddress').click(function () {
         var nameValue = $('#name').val();
         var companyValue = $('#company').val();
         var streetValue = $('#street').val();
         var cityValue = $('#city').val();
         var countyValue = $('#county').val();
         var countryValue = $('#country').val();
         var zipcodeValue = $('#zipcode').val();
         var telValue = $('#telephone').val();
         var emailValue = $('#email').val();
         var serviceValue = $('#postageservice').val();

         var url = './MailHandler.ashx?act=u&id=0109&ebayuserid=' + eBayUserID + '&orderid=' + orderID + '&name=' + nameValue + 
                   '&company=' + companyValue + '&street=' + streetValue + '&city=' + cityValue + '&county=' + countyValue +
                   '&country=' + countryValue + '&zipcode=' + zipcodeValue + '&telephone=' + telValue + '&email=' + emailValue +
                   '&postageservice=' + serviceValue;
         
         $.getJSON(
           url,
           function (data) {
             if (data.retVal == 0) {
               alert('保存成功');
             }
             else {
               alert(data.retMsg);
             }
           });
       });
     });
     var request = {
       QueryString: function (val) {
         var url = window.location.search;
         var re = new RegExp('' + val + '=([^&?]*)', 'ig');
         return ((url.match(re)) ? (url.match(re)[0].substr(val.length + 1)) : null);
       }
     };
    </script>
  </head>
  <body>
    <div id="container">
      <div id="header">
        <div id="address">
          <h3>收件人地址</h3>
          <table>
            <tr>
              <td>联系人</td>
              <td><input id="name" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>公司</td>
              <td><input id="company" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>街道</td>
              <td><input id="street" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>城市</td>
              <td><input id="city" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>州/省</td>
              <td><input id="county" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>国家</td>
              <td><input id="country"  type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>邮编</td>
              <td><input id="zipcode"  type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>电话</td>
              <td><input id="telephone" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>邮箱</td>
              <td><input id="email" type="text" style="width:200px;" /></td>
            </tr>
            <tr>
              <td>发货方式</td>
              <%--<td><input id="Text1" type="text" runat="Server" /></td>--%>
              <td><input id="postageservice" class="easyui-combobox" style="width:200px;" /></td>
            </tr>
          </table>
          <a id="btnsaveaddress" class="easyui-linkbutton" style="float:right;">保存</a>
        </div>
        <div id="ebayaddress" class="easyui-panel" title="eBay地址" cls="heBayAddress" style="width:350px;padding: 0 10px;">
          <span id="ebayname"></span><br /> 
          <span id="ebaystreet"></span><br />
          <span id="ebaycity"></span><br />
          <span id="ebaycounty"></span><br />
          <span id="ebaycountry"></span><br />
          <span id="ebayzipcode"></span><br />
          <%--<span id="ebaytelephone" /><br />--%>
          <%--<span id="ebayemail" /><br />--%>
          <a id="btnimportinfo" class="easyui-linkbutton">引用eBay地址</a>
        </div>
      </div>
      <div id="midbody">
        <table id="product" style="height:150px"></table>
        <div>
          实际发货方式: <input id="shippingtype" type="text" readonly="true" />
          发货公司: <input id="shippingcarrier" type="text" readonly="true"/>
          理论邮费: <input id="shippingamount" type="text" style="width:50px;"/>
        </div>
        <div style="float:right;margin-top:10px;">
          <%--<a id="btnsave" class="easyui-linkbutton">保存</a>--%>
          <a id="btnresend" class="easyui-linkbutton" >重发</a>
          <a id="btnrefund" class="easyui-linkbutton">退款</a>
        </div>
      </div>
    </div>
    <div id="mm" style="width:75px;">
      <div id="mm-add">增加</div>
      <div id="mm-modify">修改</div>
      <div id="mm-delete">删除</div>
    </div>
  </body>
</html>
